class Game_Player < Game_Character
  def jiguanmen1(e)
    return if @wait_count!=nil && @wait_count>0
    for i in e.event.pages
      if i.list[0].code==355
        a=i.list[0].parameters[0]
        if a.include?("x1=")
          for y in a.split("y1=")[1].to_i...a.split("y2=")[1].to_i+1
            for x in a.split("x1=")[1].to_i...a.split("x2=")[1].to_i+1
              jiguanmen2(x,y)
            end
          end
        elsif a.include?("c=")
          index=0
          script=""
          while i.list[index].code==655 or i.list[index].code==355
            script+=i.list[index].parameters[0]+"\n"
            break if i.list[index].parameters[0].include?(";@sw=true")
            index+=1 
          end
          for i in eval(script.split(";@sw=true")[0])
            jiguanmen2(i[0],i[1])
          end
        end
      end
      break
    end
    @wait_count=40
  end
  def jiguanmen2(x,y)
    if $game_map.have_an_event?(x,y)
      iid=$game_map.check_event(x,y)
      $game_map.events[iid].flash=true if \
      $game_map.events[iid].event.name[0,6]=="怪物"
    end 
  end
  alias jgm_check_event_trigger_touch check_event_trigger_touch
  def check_event_trigger_touch(x,y)
    return false if $game_system.map_interpreter.running?
    for event in $game_map.events.values
      if event.x==x and event.y==y && event.event.name=="机关门" && event.character_name=="Event01-Door04"  && event.pattern==3
        jiguanmen1(event)
        return false
      end
    end
    jgm_check_event_trigger_touch(x,y)
  end
  alias jgm_update update
  def update
    @wait_count-=1 if @wait_count!=nil && @wait_count>0
    jgm_update
  end 
end
class Sprite_Character < RPG::Sprite
  alias jgm_update update
  def update
    if @character.flash!=nil
      self.flash(Color.new(255, 255, 255),10)
      @character.flash=nil
    end;jgm_update 
  end
end
class Game_Character
  attr_accessor:flash
end